/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


/**
 * @file
 * @brief Generic functions to manage a 2D selection.
 */


#ifndef PLANET_WARS_2D_RT_CORE_SELECTION_2D_GENERIC_H
#define PLANET_WARS_2D_RT_CORE_SELECTION_2D_GENERIC_H


#include "PlanetWars2dRT-core/utils/rectangle_generic.h"


enum selection_2d_type
  {
    SELECTION_2D_TYPE_RECTANGLE
  };
typedef enum selection_2d_type selection_2d_type;


enum selection_state
  {
    SELECTION_STATE_NULL      /* selection not even started         */,
    SELECTION_STATE_NOT_FINAL /* selection valid but can change     */,
    SELECTION_STATE_FINAL     /* selection valid changeable to null */
  };
typedef enum selection_state selection_state;

/**
 * @brief Define a 2D selection of specified type.
 * @param type A type
 */
#define DEFINE_SELECTION_2D_STRUCT(a_type)			\
  struct selection_2d_##a_type					\
  {								\
    enum  selection_state    state;				\
    enum  selection_2d_type  type;				\
    union							\
    {								\
      rectangle_##a_type rectangle;				\
    } zone;							\
  };								\
  typedef struct selection_2d_##a_type selection_2d_##a_type;


#define SELECTION_2D_GENERIC_INIT_FIRST_TIME_ONLY(a_selection) \
  (a_selection).state = SELECTION_STATE_NULL;		       \
  (a_selection).type  = SELECTION_2D_TYPE_RECTANGLE;


#endif
